/*
 * @Authoryour name
 * @Date2020-11-30 22:25:00
 * @LastEditTime2020-11-30 22:25:00
 * @LastEditorsyour name
 * @DescriptionIn User Settings Edit
 * @FilePath\STM32H750_FreeRTOS\Bsp\bsp_uart\bsp_uart.h
 */ 
#ifndef BSP_UART_H_
#define BSP_UART_H_

#include "common_types.h"
#include "stm32h7xx_ll_usart.h"
#include "stm32h7xx_ll_gpio.h"
#include "stm32h7xx_ll_dmamux.h"
#include "stm32h7xx_ll_dma.h"
#include "stm32h7xx_ll_bus.h"

#define DEBUG_UART                  UART4
#define DEBUG_UART_IO_CLK_EN()          \
    {                                   \
        LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOA);\
        LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOI);\
    }                                   

#define DEBUG_UART_RX_PIN           GPIO_PIN_9          
#define DEBUG_UART_RX_PORT          GPIOI
#define DEBUG_UART_RX_AF
#define DEBUG_UART_TX_PIN           GPIO_PIN_0
#define DEBUG_UART_TX_PORT          GPIOA
#define DEBUG_UART_TX_AF

#define DEBUG_UART_CLK_EN()         LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4)
#define DEBUG_UART_BAUDRATE         115200

#define DEBUG_UART_RX_BUFFER_SIZE   512

#define DEBUG_UART_DMA_CLK_EN()     LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1)

#define DEBUG_UART_RX_DMA           DMA1
#define DEBUG_UART_RX_DMA_STREAM    LL_DMA_STREAM_0

typedef struct uart_rx
{
    uint16_t old_pos;
    uint8_t* rx_buffer;
}uart_rx_t;

extern uint8_t debug_uart_rx_buffer[DEBUG_UART_RX_BUFFER_SIZE];
extern uart_rx_t debug_uart_rx;

extern void bsp_uart_init(void);
extern uint8_t bsp_debug_uart_write(char *buffer, uint16_t len);
extern uint8_t bsp_debug_uart_write_one(char ch);
extern uint16_t uart_curr_pos_get(void);
extern uint16_t uart_buffer_size_get(void);

#endif /* BSP_UART_H_ */

